package dgcptic.interventions.model;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Query;



import dgcptic.interventions.utils.EMF;

public class DemandeurFactory {

	public void persist(Demandeur d) {
		System.out.println("DemandeurFactory persist " + d);
		EntityManagerFactory emf = EMF.get();
		EntityManager em = emf.createEntityManager();
		em.persist(d);
		em.close();
		System.out.println("DemandeurFactory persist done");
	}

	
	public Demandeur getDemander(String login){
		EntityManagerFactory emf = EMF.get();
		EntityManager em = emf.createEntityManager();
		Query query = em.createQuery("select from " + Demandeur.class.getName()+" where nom = :1" );
		query.setParameter(1, login);
		List<Demandeur> list = query.getResultList();
		if(list.size()==0) {
			return null;
		}
		else{
			return list.get(0);
		}
	}
}
